home *** CD-ROM | disk | FTP | other *** search
/ Java Programmer's Toolkit / Java Programmer's Toolkit.iso / src / java / awt / frame~1.jav < prev    next >
Encoding:
Text File  |  1996-01-12  |  6.1 KB  |  244 lines

  1. /*
  2.  * @(#)Frame.java    1.38 95/12/01 Sami Shaio
  3.  *
  4.  * Copyright (c) 1995 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19. package java.awt;
  20.  
  21. import java.awt.peer.FramePeer;
  22.  
  23. /**
  24.  * A Frame is a top-level window with a title.
  25.  * The default layout for a frame is BorderLayout.
  26.  *
  27.  * @version     1.38, 12/01/95
  28.  * @author     Sami Shaio
  29.  */
  30. public class Frame extends Window implements MenuContainer {
  31.     public static final int    DEFAULT_CURSOR           = 0;
  32.     public static final int    CROSSHAIR_CURSOR         = 1;
  33.     public static final int    TEXT_CURSOR              = 2;
  34.     public static final int    WAIT_CURSOR             = 3;
  35.     public static final int    SW_RESIZE_CURSOR         = 4;
  36.     public static final int    SE_RESIZE_CURSOR         = 5;
  37.     public static final int    NW_RESIZE_CURSOR        = 6;
  38.     public static final int    NE_RESIZE_CURSOR         = 7;
  39.     public static final int    N_RESIZE_CURSOR         = 8;
  40.     public static final int    S_RESIZE_CURSOR         = 9;
  41.     public static final int    W_RESIZE_CURSOR             = 10;
  42.     public static final int    E_RESIZE_CURSOR            = 11;
  43.     public static final int    HAND_CURSOR            = 12;
  44.     public static final int    MOVE_CURSOR            = 13;    
  45.     
  46.     String     title = "Untitled";
  47.     Image      icon;
  48.     MenuBar    menuBar;
  49.     boolean    resizable = true;
  50.     Image    cursorImage;
  51.     int        cursorType = DEFAULT_CURSOR;
  52.     Color    cursorFg;
  53.     Color    cursorBg;
  54.     
  55.     /**
  56.      * Constructs a new Frame that is initially invisible.
  57.      * @see Component#resize
  58.      * @see Component#show
  59.      */
  60.     public Frame() {
  61.     visible = false;
  62.     setLayout(new BorderLayout());
  63.     }
  64.     
  65.     /**
  66.      * Constructs a new, initially invisible Frame with the specified 
  67.      * title.
  68.      * @param title te specified title 
  69.      * @see Component#resize
  70.      * @see Component#show
  71.      */
  72.     public Frame(String title) {
  73.     this();
  74.     this.title = title;
  75.     }
  76.     
  77.     /**
  78.      * Creates the Frame's peer.  The peer allows us to change the look
  79.      * of the Frame without changing its functionality.
  80.      */
  81.     public synchronized void addNotify() {
  82.     peer = getToolkit().createFrame(this);
  83.     if (menuBar != null) {
  84.         menuBar.addNotify();
  85.         ((FramePeer)peer).setMenuBar(menuBar);
  86.     }
  87.     super.addNotify();
  88.     }
  89.     
  90.     /**
  91.      * Gets the title of the Frame.
  92.      * @see #setTitle
  93.      */
  94.     public String getTitle() {
  95.     return title;
  96.     }
  97.     
  98.     /**
  99.      * Sets the title for this Frame to the specified title.
  100.      * @param title the specified title of this Frame
  101.      * @see #getTitle
  102.      */
  103.     public void setTitle(String title) {
  104.     this.title = title;
  105.     FramePeer peer = (FramePeer)this.peer;
  106.     if (peer != null) {
  107.         peer.setTitle(title);
  108.     }
  109.     }
  110.     
  111.     /**
  112.      * Returns the icon image for this Frame.
  113.      */
  114.     public Image getIconImage() {
  115.     return icon;
  116.     }
  117.     
  118.     /**
  119.      * Sets the image to display when this Frame is iconized. Note that
  120.      * not all platforms support the concept of iconizing a window.
  121.      * @param image the icon image to be displayed
  122.      */
  123.     public void setIconImage(Image image) {
  124.     this.icon = image;
  125.     FramePeer peer = (FramePeer)this.peer;
  126.     if (peer != null) {
  127.         peer.setIconImage(image);
  128.     }
  129.     }
  130.     
  131.     /**
  132.      * Gets the menu bar for this Frame.
  133.      */
  134.     public MenuBar getMenuBar() {
  135.     return menuBar;
  136.     }
  137.     
  138.     /**
  139.      * Sets the menubar for this Frame to the specified menubar.
  140.      * @param mb the menubar being set
  141.      */
  142.     public synchronized void setMenuBar(MenuBar mb) {
  143.     if (menuBar == mb) {
  144.         return;
  145.     }
  146.     if (mb.parent != null) {
  147.         mb.parent.remove(mb);
  148.     }
  149.     if (menuBar != null) {
  150.         remove(menuBar);
  151.     }
  152.     menuBar = mb;
  153.     menuBar.parent = this;
  154.     
  155.     FramePeer peer = (FramePeer)this.peer;
  156.     if (peer != null) {
  157.         menuBar.addNotify();
  158.         peer.setMenuBar(menuBar);
  159.     }
  160.     }
  161.     
  162.     /**
  163.      * Removes the specified menu bar from this Frame.
  164.      */
  165.     public synchronized void remove(MenuComponent m) {
  166.     if (m == menuBar) {
  167.         FramePeer peer = (FramePeer)this.peer;
  168.         if (peer != null) {
  169.         menuBar.removeNotify();
  170.         menuBar.parent = null;
  171.         peer.setMenuBar(null);
  172.         }
  173.         menuBar = null;
  174.     }
  175.     }
  176.     
  177.     /**
  178.      * Disposes of the Frame. This method must
  179.      * be called to release the resources that
  180.      * are used for the frame.
  181.      */
  182.     public synchronized void dispose() {
  183.     if (menuBar != null) {
  184.         remove(menuBar);
  185.             menuBar = null;
  186.     }
  187.         super.dispose();
  188.     }
  189.     
  190.     /**
  191.      * Returns true if the user can resize the Frame.
  192.      */
  193.     public boolean isResizable() {
  194.     return resizable;
  195.     }
  196.     
  197.     /**
  198.      * Sets the resizable flag.
  199.      * @param resizable true if resizable; false otherwise.
  200.      */
  201.     public void setResizable(boolean resizable) {
  202.     this.resizable = resizable;
  203.     FramePeer peer = (FramePeer)this.peer;
  204.     if (peer != null) {
  205.         peer.setResizable(resizable);
  206.     }
  207.     }
  208.     
  209.     /**
  210.      * Set the cursor image to a predefined cursor.
  211.      * @param cursorType one of the cursor constants defined above.
  212.      */
  213.     public void setCursor(int cursorType) {
  214.     if (cursorType < DEFAULT_CURSOR || cursorType > MOVE_CURSOR) {
  215.         throw new IllegalArgumentException("illegal cursor type");
  216.     }
  217.     this.cursorType = cursorType;
  218.     if (peer != null) {
  219.         ((FramePeer)peer).setCursor(cursorType);
  220.     }
  221.     }
  222.  
  223.     /**
  224.      * Return the cursor type
  225.      */
  226.     public int getCursorType() {
  227.     return cursorType;
  228.     }
  229.     
  230.     /**
  231.      * Returns the parameter String of this Frame.
  232.      */
  233.     protected String paramString() {
  234.     String str = super.paramString();
  235.     if (resizable) {
  236.         str += ",resizable";
  237.     }
  238.     if (title != null) {
  239.         str += ",title=" + title;
  240.     }
  241.     return str;
  242.     }
  243. }
  244.